# PowerShell script to check DLL dependencies
Write-Host "Checking funasr_flutter.dll dependencies..." -ForegroundColor Green

# Get current directory
$currentDir = Get-Location
$dllPath = "$currentDir\onnxruntime\build\bin\Release\funasr_flutter.dll"

# Check if DLL file exists
if (-not (Test-Path $dllPath)) {
    Write-Host "Error: Cannot find file $dllPath" -ForegroundColor Red
    exit 1
}

Write-Host "Analyzing: $dllPath" -ForegroundColor Yellow

# Check dependencies
Write-Host "`nChecking dependency libraries..." -ForegroundColor Cyan
try {
    # Try to list DLL files in dependency directories
    $onnxRuntimeDir = "$currentDir\onnxruntime\onnxruntime-win-x64-1.16.1\lib"
    $ffmpegDir = "$currentDir\onnxruntime\ffmpeg-master-latest-win64-gpl-shared\bin"
    
    if (Test-Path $onnxRuntimeDir) {
        Write-Host "`nONNX Runtime dependency libraries:" -ForegroundColor Cyan
        Get-ChildItem -Path $onnxRuntimeDir -Filter "*.dll" | ForEach-Object {
            Write-Host "  $($_.Name)"
        }
    }
    
    if (Test-Path $ffmpegDir) {
        Write-Host "`nFFmpeg dependency libraries:" -ForegroundColor Cyan
        Get-ChildItem -Path $ffmpegDir -Filter "*.dll" | ForEach-Object {
            Write-Host "  $($_.Name)"
        }
    }
} catch {
    Write-Host "Warning: Unable to list dependency library files" -ForegroundColor Yellow
}

# Check files in target directory
$targetDir = "$currentDir\build\windows\x64\runner\Debug"
if (Test-Path $targetDir) {
    Write-Host "`nDLL files in target directory:" -ForegroundColor Cyan
    Get-ChildItem -Path $targetDir -Filter "*.dll" | ForEach-Object {
        Write-Host "  $($_.Name)"
    }
}

Write-Host "`nCheck completed. Please ensure all required DLL files have been copied to the application directory." -ForegroundColor Green